package assignment04;

import java.util.ArrayList;
import java.util.List;

import gnu.trove.map.TObjectIntMap;
import gnu.trove.map.hash.TObjectIntHashMap;

public class IntIndexer {
	List<String> objects;
	TObjectIntMap<String> indexes;
	
	public String get(int index) {
		return objects.get(index);
	}
	
	public int size() {
		
		return objects.size();
	}
	
	public int indexOf(Object o) {
		int index = indexes.get(o);
		if (0 == index) {
			return -1;
		}
		return index;
	}
	
	public int addAndGetIndex(String s) {
		int index = indexes.get(s);
		if (index != 0) {
			return index;
		}
		// Else, add
		int newIndex = size();
		objects.add(s);
		indexes.put(s, newIndex);
		return newIndex;
	}
	
	
	public IntIndexer() {
		objects = new ArrayList<String>();
		indexes = new TObjectIntHashMap<String>();
	}
	
	
	public static void main(String[] args) {
		IntIndexer indexer = new IntIndexer();
		System.out.println(indexer.indexes.get("abc"));
	}
	
}
